import {
	defineStore,
} from 'pinia'
import {ref} from 'vue'

import {
	addressList
} from '@/api/api.js'

export const useSysStore = defineStore("sys", () => {
	const statusBarHeight = ref(0)
	const navBarHeight = ref(0)
	const screenWidth = ref(0)
	const provinces = ref([])
	const cities = ref([])
	const districts = ref([])
	
	function setStatusBarHeight(value) {
		statusBarHeight.value = value
	}
	function setNavBarHeight(value) {
		navBarHeight.value = value
	}
	function setScreenWidth(value) {
		screenWidth.value = value
	}
	function getAddressList() {
		addressList().then(({ result, status }) => {
			if (status === 0) {
				const [p, c, d] = result;
				provinces.value = p;
				cities.value = c;
				districts.value = d;
			}
		})
	}
	return {
		statusBarHeight,
		navBarHeight,
		screenWidth,
		setStatusBarHeight,
		setNavBarHeight,
		setScreenWidth,
		getAddressList,
		provinces,
		cities,
		districts,
	}
})